package app.nbdevices.controller;

import app.nbdevices.api.dto.*;
import app.nbdevices.api.service.ApiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class ApiController {

    @Autowired
    ApiService apiService;

    @GetMapping("/api/region_orgalizationList")
    public ResponseCode getRegOrg(){
        return ResponseCode.success(apiService.getRegOrgList());
    }


    @GetMapping("/test")
    public ResponseCode getTest(){
        System.out.println("test");
        return ResponseCode.success();
    }

    @GetMapping("/api/user_getList")
    public ResponseCode getUserList(){
        return ResponseCode.success(apiService.getUserInfoList());
    }

    @GetMapping("/api/moduleList")
    public ResponseCode getModuleList(){
        return ResponseCode.success(apiService.getModuleList());
    }

    @GetMapping("/api/facilitiesList")
    public ResponseCode getFacList(){
        return ResponseCode.success(apiService.getFacRegOrgDto());
    }

    @PostMapping("/api/facilities_codeList")
    public ResponseCode setFacilities_code(@RequestBody List<FacCode> facCodeList){
        List<String> res=apiService.updateFacCode(facCodeList);
            if(res.size()==0){
                return ResponseCode.success();
            }else{
                return ResponseCode.error(res);
            }
    }

    @GetMapping("/api/deviceList")
    public ResponseCode getDeviceList(){
        return ResponseCode.success(apiService.getDevInfoList());
    }

    @PostMapping("/api/institution")
    public ResponseCode setInstitutionList(@RequestBody InstitutionDto ins){
        return ResponseCode.success(apiService.updateInsReg(ins));
    }

    @PostMapping("/api/user_PostList")
    public ResponseCode setuserPostList(@RequestBody UserPostList userPostList){
        System.out.println(userPostList);
        return ResponseCode.success(apiService.savaUserList(userPostList));
    }

    @PostMapping("/api/user_status_role")
    public ResponseCode getUserStatus(@RequestBody OppenidDto oppenid){
        return ResponseCode.success(apiService.getUserStatus(oppenid.getOppenid()));
    }

    @PostMapping("/api/need_controle")
    public ResponseCode getNeedControle(@RequestBody List<String> devCodes){
        return ResponseCode.success(apiService.getCodes(devCodes));
    }

    @PostMapping("/api/regionIs_Exist")
    public ResponseCode getRegionIs_Exist(@RequestBody RegionNameModle regionNameModle){
        return ResponseCode.success(apiService.getRrgionIsExist(regionNameModle.getName()));
    }

    @PostMapping("/api/froze-user")
    public ResponseCode frozeUser(@RequestBody FrozenModle frozenModle){
        apiService.setUserFrozen(frozenModle.getOppenId(),frozenModle.getIsFrozen());
        return ResponseCode.success();
    }
}
